package com.jxw.update;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.jht.engine.platsign.PlatSignatureWrapper;
import com.jxw.launcher.BaseThemeActivity;
import com.jxw.launcher.R;
import com.jxw.launcher.util.CheckFileAndDown;
import com.jxw.launcher.util.ReceiverUtil;
import com.jxw.launcher.view.UIGroupButtomView;
import com.zzj.ziputil.ArchiverManager;
import com.zzj.ziputil.IArchiverListener;
import java.util.ArrayList;
import java.util.List;
import me.jessyan.autosize.internal.CancelAdapt;

/* loaded from: classes.dex */
public class UpdateActivity extends BaseThemeActivity implements RadioGroup.OnCheckedChangeListener, CancelAdapt {
    RadioButton button2;
    private AlertDialog exitDialog;
    PlatSignatureWrapper mPlatformSignature;
    private AlertDialog netDialog;
    List<String> paths;
    RadioGroup radioGroup;
    private UIGroupButtomView rb_channe2;
    private UIGroupButtomView rb_channe3;
    private UIGroupButtomView rb_channe4;
    private UIGroupButtomView rb_channe5;
    private UIGroupButtomView rb_channel;
    private Fragment currentFragment = new Fragment();
    private FragmentOta first = new FragmentOta();
    private Fragment2 second = new Fragment2();
    private Fragment3 third = new Fragment3();
    private Fragment4 four = new Fragment4();
    private Fragment5 five = new Fragment5();
    private BroadcastReceiver networkReceiver = new BroadcastReceiver() { // from class: com.jxw.update.UpdateActivity.2
        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if (ReceiverUtil.ACTION_CONNECTIVITY_ACTION.equals(intent.getAction())) {
                NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
                if (activeNetworkInfo == null) {
                    UpdateActivity.this.showNetDialog();
                } else if (!activeNetworkInfo.isConnected()) {
                    UpdateActivity.this.showNetDialog();
                } else if (activeNetworkInfo.getType() == 1) {
                } else {
                    activeNetworkInfo.getType();
                }
            }
        }
    };

    public void allDown(View view) {
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.jxw.launcher.BaseThemeActivity, com.jxw.launcher.BaseActivity, android.support.v4.app.FragmentActivity, android.support.v4.app.SupportActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_update);
        this.paths = new ArrayList();
        CheckFileAndDown.isAllDownSus = true;
        initViews();
        this.rb_channe3.setVisibility(8);
        switchFragment(this.first).commit();
        registerReceiver(this.networkReceiver, new IntentFilter(ReceiverUtil.ACTION_CONNECTIVITY_ACTION));
    }

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onBackPressed() {
        super.onBackPressed();
    }

    public void onExit(View view) {
        Fragment fragment = this.currentFragment;
        Fragment3 fragment3 = this.third;
        if (fragment == fragment3) {
            if (fragment3.pb_progressbar.getVisibility() == 0) {
                showExitDialog("还未校验完成， 确定退出吗 ？");
                return;
            }
        } else {
            Fragment4 fragment4 = this.four;
            if (fragment == fragment4 && fragment4.isDownload) {
                showExitDialog("还未完成下载， 确定退出吗 ？");
                return;
            }
        }
        finish();
    }

    @Override // android.app.Activity, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i == 4) {
            Fragment fragment = this.currentFragment;
            Fragment3 fragment3 = this.third;
            if (fragment == fragment3) {
                if (fragment3.pb_progressbar.getVisibility() == 0) {
                    showExitDialog("还未校验完成， 确定退出吗 ？");
                    return true;
                }
            } else {
                Fragment4 fragment4 = this.four;
                if (fragment == fragment4 && fragment4.isDownload) {
                    showExitDialog("还未完成下载， 确定退出吗 ？");
                    return true;
                }
            }
        }
        return super.onKeyDown(i, keyEvent);
    }

    private void archiver(String str, String str2) {
        final ProgressDialog progressDialog = new ProgressDialog(this, 3);
        progressDialog.setMessage("解压中，请稍候...");
        progressDialog.setTitle("解压文件");
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setProgressStyle(1);
        ArchiverManager.getInstance().doUnArchiver(str, str2, "", new IArchiverListener() { // from class: com.jxw.update.UpdateActivity.1
            @Override // com.zzj.ziputil.IArchiverListener
            public void onStartArchiver() {
                UpdateActivity.this.runOnUiThread(new Runnable() { // from class: com.jxw.update.UpdateActivity.1.1
                    @Override // java.lang.Runnable
                    public void run() {
                        progressDialog.show();
                    }
                });
            }

            @Override // com.zzj.ziputil.IArchiverListener
            public void onProgressArchiver(final int i, final int i2) {
                UpdateActivity.this.runOnUiThread(new Runnable() { // from class: com.jxw.update.UpdateActivity.1.2
                    @Override // java.lang.Runnable
                    public void run() {
                        progressDialog.setMax(i2);
                        progressDialog.setProgress(i);
                    }
                });
            }

            @Override // com.zzj.ziputil.IArchiverListener
            public void onEndArchiver() {
                UpdateActivity.this.runOnUiThread(new Runnable() { // from class: com.jxw.update.UpdateActivity.1.3
                    @Override // java.lang.Runnable
                    public void run() {
                        progressDialog.dismiss();
                    }
                });
            }
        });
    }

    private FragmentTransaction switchFragment(Fragment fragment) {
        FragmentTransaction beginTransaction = getSupportFragmentManager().beginTransaction();
        if (!fragment.isAdded()) {
            Fragment fragment2 = this.currentFragment;
            if (fragment2 != null) {
                beginTransaction.hide(fragment2);
            }
            beginTransaction.add(R.id.fragment, fragment, fragment.getClass().getName());
        } else {
            beginTransaction.hide(this.currentFragment).show(fragment);
        }
        this.currentFragment = fragment;
        return beginTransaction;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.jxw.launcher.BaseThemeActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(this.networkReceiver);
    }

    private void initViews() {
        this.radioGroup = (RadioGroup) findViewById(R.id.group);
        this.radioGroup.setOnCheckedChangeListener(this);
        this.button2 = (RadioButton) findViewById(R.id.rb_channe2);
        this.rb_channel = (UIGroupButtomView) findViewById(R.id.rb_channel);
        this.rb_channe2 = (UIGroupButtomView) findViewById(R.id.rb_channe2);
        this.rb_channe3 = (UIGroupButtomView) findViewById(R.id.rb_channe3);
        this.rb_channe4 = (UIGroupButtomView) findViewById(R.id.rb_channe4);
    }

    public void onClick(View view) {
        try {
            Intent intent = new Intent();
            intent.setClassName("com.ccapp.update.otaupgrade", "com.ccapp.update.otaupgrade.UpdateActivity");
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override // android.widget.RadioGroup.OnCheckedChangeListener
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i) {
            case R.id.rb_channe2 /* 2131231104 */:
                switchFragment(this.second).commit();
                this.rb_channe2.setTextColor(Color.parseColor("#FFFFFF"));
                this.rb_channel.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe3.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe4.setTextColor(Color.parseColor("#01B9FF"));
                return;
            case R.id.rb_channe3 /* 2131231105 */:
                switchFragment(this.third).commit();
                this.rb_channe3.setTextColor(Color.parseColor("#FFFFFF"));
                this.rb_channel.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe2.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe4.setTextColor(Color.parseColor("#01B9FF"));
                return;
            case R.id.rb_channe4 /* 2131231106 */:
                if (this.third.isDownload) {
                    radioGroup.check(R.id.rb_channe3);
                    Toast.makeText(this, "预制数据下载中", 0).show();
                } else {
                    switchFragment(this.four).commit();
                    haveNet();
                }
                this.rb_channe4.setTextColor(Color.parseColor("#FFFFFF"));
                this.rb_channel.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe3.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe2.setTextColor(Color.parseColor("#01B9FF"));
                return;
            case R.id.rb_channel /* 2131231107 */:
                switchFragment(this.first).commit();
                haveNet();
                this.rb_channel.setTextColor(Color.parseColor("#FFFFFF"));
                this.rb_channe2.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe3.setTextColor(Color.parseColor("#01B9FF"));
                this.rb_channe4.setTextColor(Color.parseColor("#01B9FF"));
                return;
            default:
                return;
        }
    }

    public void goDown() {
        this.radioGroup.setOnCheckedChangeListener(null);
        switchFragment(this.four).commit();
        this.rb_channe3.setTextColor(Color.parseColor("#FFFFFF"));
        this.rb_channel.setTextColor(Color.parseColor("#01B9FF"));
        this.rb_channe2.setTextColor(Color.parseColor("#01B9FF"));
        this.rb_channe4.setTextColor(Color.parseColor("#01B9FF"));
        this.rb_channe3.setChecked(true);
        this.radioGroup.setOnCheckedChangeListener(this);
    }

    @Override // com.jxw.launcher.BaseThemeActivity, com.jxw.launcher.BaseActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showNetDialog() {
        AlertDialog alertDialog = this.netDialog;
        if (alertDialog != null) {
            alertDialog.show();
            return;
        }
        this.netDialog = new AlertDialog.Builder(this, R.style.Theme_Transparent).create();
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_nonet, (ViewGroup) null);
        inflate.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.update.UpdateActivity.3
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                UpdateActivity.this.netDialog.cancel();
            }
        });
        inflate.findViewById(R.id.set).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.update.UpdateActivity.4
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                try {
                    UpdateActivity.this.startActivity(new Intent("android.settings.WIFI_SETTINGS"));
                    UpdateActivity.this.netDialog.cancel();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        this.netDialog.setView(inflate);
        this.netDialog.setCancelable(false);
        this.netDialog.setCanceledOnTouchOutside(false);
        this.netDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { // from class: com.jxw.update.UpdateActivity.5
            @Override // android.content.DialogInterface.OnKeyListener
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                return i == 84;
            }
        });
        this.netDialog.show();
    }

    private boolean haveNet() {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) getSystemService("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
            showNetDialog();
            return false;
        }
        return true;
    }

    private void showExitDialog(String str) {
        AlertDialog alertDialog = this.exitDialog;
        if (alertDialog != null) {
            alertDialog.show();
            return;
        }
        this.exitDialog = new AlertDialog.Builder(this, R.style.Theme_Transparent).create();
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_exitdown, (ViewGroup) null);
        ((TextView) inflate.findViewById(R.id.text2)).setText(str);
        inflate.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.update.UpdateActivity.6
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                UpdateActivity.this.exitDialog.cancel();
            }
        });
        inflate.findViewById(R.id.set).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.update.UpdateActivity.7
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (UpdateActivity.this.currentFragment == UpdateActivity.this.third) {
                    UpdateActivity.this.third.exit();
                } else if (UpdateActivity.this.currentFragment == UpdateActivity.this.four) {
                    UpdateActivity.this.four.exit();
                }
                UpdateActivity.this.exitDialog.cancel();
                UpdateActivity.this.finish();
            }
        });
        this.exitDialog.setView(inflate);
        this.exitDialog.setCancelable(false);
        this.exitDialog.setCanceledOnTouchOutside(false);
        this.exitDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { // from class: com.jxw.update.UpdateActivity.8
            @Override // android.content.DialogInterface.OnKeyListener
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                return i == 84;
            }
        });
        this.exitDialog.show();
    }
}
